#Setup Superuser account

#bug #fix for multiple web applications
$webapps = get-spwebapplication |% { $_.Url }

	foreach ($webapp in $webapps){
		
	Write-Host -ForegroundColor Yellow "Permissions: Adding Farm Account to superuser for $webapp."

	$wa=Get-SPWebApplication "$webapp"
	$wapol=$wa.Policies
	#Write-Host "Adding User to Web App : $wapol.Add($env:serviceacct,$env:serviceacct)"
	$wapkmcrawl=$wapol.Add($env:serviceacct,$env:serviceacct)
	$wapkmcrawl.PolicyRoleBindings.Add($wa.PolicyRoles["Full Control"])
	$wa.update()
	#Write-Host "Completed"

	#Write-Host "stsadm -o setproperty -propertyname portalsuperuseraccount -propertyvalue $env:serviceacct -url $env:farmurl"
	stsadm -o setproperty -propertyname portalsuperuseraccount -propertyvalue $env:serviceacct -url "$webapp"
	#Write-Host "Completed"

	Write-Host -ForegroundColor Yellow "Permissions: Adding Farm Account to superuser for $webapp. : COMPLETED"
	}